package com.student.xujiang.mysmalluse.retrofit2andrxjava2;

import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.student.xujiang.R;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.Observable;
import io.reactivex.ObservableTransformer;

/**
 *  来自 http://blog.csdn.net/gesanri/article/details/52701651#comments
 *
 *  还没测试 回去搭服务器进行测试
 *
 *
 * */

public class Retro2AndRxjava2MainActivity extends NetworkBaseActivity {

    @BindView(R.id.et_rar2_name)
    EditText etRar2Name;
    @BindView(R.id.et_rar2_password)
    EditText etRar2Password;
    @BindView(R.id.bt_rar2_send)
    Button btRar2Send;
    @BindView(R.id.activity_retro2_and_rxjava2_main)
    LinearLayout activityRetro2AndRxjava2Main;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.age)
    TextView age;

    private Observable observable;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_retro2_and_rxjava2_main);
        ButterKnife.bind(this);

    }

    @OnClick(R.id.bt_rar2_send)
    public void onClick() {
        Map<String, String> map = new HashMap<String, String>();
        map.put("name", etRar2Name.getText().toString().trim());
        map.put("password", etRar2Password.getText().toString().trim());

        observable = RetroFactory.getInstance().getUser(map);
        observable.compose((ObservableTransformer) composeFunction)
                .subscribe(new BaseObserver<User>
                (Retro2AndRxjava2MainActivity.this, pd) {

            @Override
            void onHandleSuccess(User user) {
                name.setText("姓名：" + user.getName());
                age.setText("年龄：" + user.getAge());
            }
        });

    }
}
